﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Caching;


namespace Ecommerce.Model
{
    internal class CacheModel
    {
        private static ObjectCache cache = MemoryCache.Default;

        public static void Inserir(string key, object objeto, int minutosExpirar)
        {
            if (cache[key] != null)
                cache.Remove(key);

            DateTimeOffset data = new DateTimeOffset(DateTime.Now.AddMinutes(minutosExpirar));
            cache.Add(key, objeto, data);
        }

        public static T Obter<T>(string key)
        {
            if (cache[key] == null)
                return default(T);
            else
                return (T)cache[key];
        }
    }
}
